package com.youlin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.youlin.dto.BaseDataResDto;
import com.youlin.dto.Status;
import com.youlin.dto.res.RoleResDto;
import com.youlin.entities.BygRole;
import com.youlin.mapper.BygUnitRoleMapper;
import com.youlin.service.BygRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlin.untils.BaseService;
import com.youlin.untils.MyEnum;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class BygRoleServiceImpl extends ServiceImpl<BygUnitRoleMapper, BygRole> implements BygRoleService {

    @Override
    public BaseDataResDto<List<RoleResDto>> findAllRoles() {
        QueryWrapper<BygRole> queryWrapper = new QueryWrapper<BygRole>().orderByAsc("id")
                .in("id", Arrays.asList(MyEnum.ROLE_OPERATOR_ID.getValue(), MyEnum.ROLE_REVIEWER_ID.getValue()));
        List<RoleResDto> roleResDtos = list(queryWrapper).parallelStream()
                .map(r -> BaseService.copyProperties(r, RoleResDto.class)).collect(Collectors.toList());
        return new BaseDataResDto<List<RoleResDto>>(Status.SUCCESS).setData(roleResDtos);
    }

}
